package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.entity.SetmealDish;
import com.sky.mapper.SetmealDishMapper;
import com.sky.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {
    @Autowired
    private SetmealDishMapper setmealDishMapper;

    @Override
    public Long countByDishId(Long dishId) {

        LambdaQueryWrapper<SetmealDish> lambdaQueryWrapper = new LambdaQueryWrapper<SetmealDish>()
                .eq(SetmealDish::getDishId, dishId);

        return setmealDishMapper.selectCount(lambdaQueryWrapper);
    }

    @Override
    public void createBatch(List<SetmealDish> setmealDishList) {
        // 逐个插入
        for (SetmealDish setmealDish : setmealDishList) {
            setmealDishMapper.insert(setmealDish);
        }

    }

    @Override
    public void deleteBySetmealId(Long setmealId) {
        setmealDishMapper.delete(
                new LambdaQueryWrapper<SetmealDish>()
                        .eq(SetmealDish::getSetmealId, setmealId)
        );
    }

    @Override
    public List<SetmealDish> getBySetmealId(Long setmealId) {

        return lambdaQuery()
                .eq(SetmealDish::getSetmealId, setmealId)
                .list();


    }
}
